package zr.component;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

import zr.dao.Player;
import zr.util.Logger;

public class PlayerInfoPane extends JPanel{

	private final static org.apache.log4j.Logger logger = Logger
			.getInstance(PlayerInfoPane.class);
	Font font=new Font("微软雅黑",1,30);
	JLabel playerName=new JLabel();
	JLabel leftTime=new JLabel();
	JLabel ip=new JLabel();
	JLabel playerNameLabel=new JLabel("玩家姓名:");
	JLabel leftTimeLabel=new JLabel("剩余时间:");
	JLabel ipLabel=new JLabel("IP:");

	public PlayerInfoPane(Player player){
		super();
		this.setBackground(Color.LIGHT_GRAY);
		this.setLayout(new GridLayout(3,2,2,2));
		this.add(playerNameLabel);
		this.add(playerName);
		playerName.setFont(font);
		setPlayerName(player.getName());
		this.add(leftTimeLabel);
		this.add(leftTime);
		leftTime.setFont(font);
		setLeftTime(player.getLeftTime());
		this.add(ipLabel);
		this.add(ip);
		setIP(player.getIp());
		this.setBorder(BorderFactory.createTitledBorder("玩家信息"));

		logger.info("玩家"+player+"加入");
	}

	private void setIP(String ipStr) {
		ip.setText(ipStr);
	}

	public void setPlayerName(String name){
		playerName.setText(name);
	}
	public void setLeftTime(String time){
		leftTime.setText(time);
	}

	public void setColor(Color color) {
		this.setForeground(color);
		playerName.setForeground(color);
		leftTime.setForeground(color);
		ip.setForeground(color);
		playerNameLabel.setForeground(color);
		leftTimeLabel.setForeground(color);
		ipLabel.setForeground(color);
	}
	
}
